package com.fgba.express.util;

import java.util.Date;
import java.util.regex.Pattern;

public class CommonUtils {


    public static boolean isNumeric(String str) {
        Pattern pattern = Pattern.compile("[0-9]*");
        return pattern.matcher(str).matches();
    }

    public static String toString(String[] strings, String regex, int start, int end) {
        StringBuffer sb = new StringBuffer();
        for (int i = start; i < end; i++) {
            if (!NullChecker.isNullOrEmpty(strings[i])) {
                sb.append(strings[i]);
            if (i != end - 1) {
                sb.append(regex);
            }
            }
        }
        return sb.toString();
    }

    /**
     * 判断a,b是否相等
     *
     * @param a
     * @param b
     * @return
     */
    public static Boolean equals(Object a, Object b) {
        if (a == null) {
            if (b == null) {
                return true;
            }

            return false;
        }
        if (b == null) {
            return false;
        }

        if (a instanceof String) {
            return ((String) a).equals(b);
        }
        if (a instanceof Date) {
            return ((Date) a).equals(b);
        }
        if (a instanceof Integer) {
            return ((Integer) a).equals(b);
        }
        if (a instanceof Long) {
            return ((Long) a).equals(b);
        }
        if (a instanceof Byte) {
            return ((Byte) a).equals(b);
        }
        if (a instanceof Boolean) {
            return ((Boolean) a).equals(b);
        }

        return a.equals(b);
    }
}
